package com.jeesite.modules.jdProduct.utils;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.jeesite.common.entity.Page;
import com.jeesite.common.utils.HttpRequest;
import com.jeesite.modules.jdProduct.dao.dto.*;
import com.jeesite.modules.jdProduct.vo.ProductSkuChecVo;
import com.jeesite.modules.jdProduct.vo.ProductStateMessagePo;
import com.jeesite.modules.pay.totalPay.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.modules.goods.entity.ZtColor;
import com.jeesite.modules.goods.entity.ZtGoods;
import com.jeesite.modules.goods.entity.ZtGoodsOrder;
import com.jeesite.modules.goods.entity.ZtSpecifications;
import com.jeesite.modules.goods.service.ZtColorService;
import com.jeesite.modules.goods.service.ZtGoodsOrderService;
import com.jeesite.modules.goods.service.ZtGoodsService;
import com.jeesite.modules.goods.service.ZtSpecificationsService;
import com.jeesite.modules.jdProduct.contact.ApiUrl;
import com.jeesite.modules.jdProduct.entity.Product;
import com.jeesite.modules.jdProduct.entity.ProductPool;
import com.jeesite.modules.jdProduct.entity.Productimg;
import com.jeesite.modules.pay.totalPay.util.HttpXmlUtils;
import com.jeesite.modules.task.TaskUtils;

@Controller
public class ProductPoolUtils {
	
	public static ExecutorService cachedThreadPool;
	
	@Autowired
	private ZtGoodsService ztGoodsService;
	
	@Autowired
	private ZtColorService ztColorService;
	
	@Autowired
	private ZtSpecificationsService ztSpecificationsService;
	
	@Autowired
	private ZtGoodsOrderService ztGoodsOrderService;
	/**
	 * 1.1.2获取商品池
	 * @return
	 */
	public static List<ProductPool> getProductPool(){
		String params=ApiUrl.getParams("biz.product.PageNum.query", "");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		List<ProductPool> ppList=new ArrayList<ProductPool>();
		if(StringUtils.isNotBlank(resultToken)){
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_PageNum_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONArray ja=job.getJSONArray("result");
				if(ja!=null && ja.size()>0){
					for(int i=0;i<ja.size();i++){
						JSONObject jj=ja.getJSONObject(i);
						ProductPool pp=new ProductPool();
						
						pp.setName(jj.getString("name"));
						pp.setPageNum(jj.get("page_num").toString());
						ppList.add(pp);
					}
				}
			}
		}
		return ppList;
	}
	/**
	 *1.1.3 查询池内商品编号接口
	 */
	public static void querySku(){
		String params=ApiUrl.getParams("biz.product.sku.query", "{\"pageNum\": \"1\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_sku_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				String result=job.getString("result");//sku ,分隔
				
			}
		}
		
	}
	
	
	/**
	 *
	 */
	public static List<Long> getSkuByPageNo(String pageNum,String pageNo){
		List<Long> skuidsList=new ArrayList<Long>();
		
		String params=ApiUrl.getParams("jd.biz.product.getSkuByPage", "{\"pageNum\": \""+pageNum+"\",\"pageNo\":\""+pageNo+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("jd_biz_product_getSkuByPage_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");//sku ,分隔
				
				JSONArray skus=result.getJSONArray("skuIds");
				
				if(skus!=null && skus.size()>0){
					for(int i=0;i<skus.size();i++){
					long skuid=(long) skus.get(i);
					skuidsList.add(skuid);
					}
				}
				
				
				
			}
		}
		return skuidsList;
	}
	/**
	 * 1.1.4获取池内商品编号接口
	 */
	public static List<Long> getSkuByPage(String pageNum,String pageNo){
		List<Long> skuidsList=new ArrayList<Long>();
		
		String params=ApiUrl.getParams("jd.biz.product.getSkuByPage", "{\"pageNum\": \""+pageNum+"\",\"pageNo\":\""+pageNo+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("jd_biz_product_getSkuByPage_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");//sku ,分隔
				int pageCount=result.getInteger("pageCount"); 
				JSONArray skus=result.getJSONArray("skuIds");
				
				if(skus!=null && skus.size()>0){
					for(int i=0;i<skus.size();i++){
					long skuid=Long.valueOf(skus.get(i).toString());
					skuidsList.add(skuid);
					}
				}
				
				if(pageCount>1){
					for(int i=2;i<=pageCount;i++){
						List<Long> skup=getSkuByPageNo(pageNum,i+"");
						if(skup!=null && skup.size()>0){
							skuidsList.addAll(skup);
						}
					}
				}
				
			}
		}
		return skuidsList;
	}
	
	/**
	 * 1.1.5  查询商品详细信息接口
	 */
	public static ZtGoods productDetail(long sku){
		String params=ApiUrl.getParams("biz.product.detail.query", "{\"sku\": "+sku+",\"isShow\":true}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		ZtGoods product=new ZtGoods();
		Date da=new Date();
		if(StringUtils.isNotBlank(resultToken)){
		
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_detail_query_response");
			boolean success=false;
			try{
			 success=job.getBoolean("success");
			}catch(Exception ex){
				return null;
			}
			if(success){
				JSONObject result=job.getJSONObject("result");//sku ,分隔
				
				String saleUnit=result.getString("saleUnit");
				String weight=result.getString("weight");
				String productArea=result.getString("productArea");
				String wareQD=result.getString("wareQD");
				String imagePath=result.getString("imagePath");
				String param=result.getString("param");
				int state=result.getInteger("state");
				
				String shouhou=result.getString("shouhou");
				String brandName=result.getString("brandName")==null?"":result.getString("brandName").trim();
				String upc=result.getString("upc");
				String appintroduce="";
				if(result.get("appintroduce")!=null){
					try{
					appintroduce=result.get("appintroduce").toString();
					//System.out.println(appintroduce);
					//System.out.println("----------------------------");
					/*String introduction=result.get("introduction").toString();
					System.out.println(introduction);*/
					}catch(Exception ex){
						appintroduce="";
					}
				}
				
				String category=result.getString("category");
				String name=result.getString("name");
				String introduction=result.getString("introduction");
				
				product.setCode(sku+"");
				//product.setSaleUnit(saleUnit);
			//	product.setWeight(weight);
				//product.setProductArea(productArea);
				product.setRemarks(wareQD);
				product.setImg("http://img13.360buyimg.com/n1/"+imagePath);
				product.setQcode("http://img13.360buyimg.com/n12/"+imagePath);
				product.setState(state);
				product.setTitle(name);
				product.setBrandName(brandName);
				product.setKeys(product.getBrandName());
				//product.setUpc(upc);
				introduction.replaceAll("\n","").replaceAll("\t","");
			/*	if(StringUtils.isNotBlank(appintroduce) ||!"null".equals(appintroduce)){
				appintroduce=appintroduce.replaceAll("/sku/", "http://img13.360buyimg.com/n0/");
				}else{
					appintroduce=introduction;
					if(StringUtils.isNotBlank(appintroduce) ||!"null".equals(appintroduce)){
						appintroduce=appintroduce.replaceAll("/sku/", "http://img13.360buyimg.com/n0/");
					}
				}*/
				
				/*if(StringUtils.isNotBlank(appintroduce)){
					int lastMap=appintroduce.lastIndexOf("<map");
					int lastMapEnd=appintroduce.lastIndexOf("</map>");
					
					
					
				}*/
				
			//	去掉/sku/，前面加
				//product.setContent(appintroduce);
				product.setType(category);
				
				product.setContent(introduction);
				product.setCreateDate(da);
				
			}
		}
		return product;
	}

	/**
	 *  查询商品详细信息
	 * @param sku
	 * @return
	 */
	public static String queryProductDetail(String sku){
		String params=ApiUrl.getParams("biz.product.detail.query", "{\"sku\": "+sku+",\"isShow\":false}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		MapUtils parse = GsonUtil.parse(resultToken, MapUtils.class);
		Map<String,Object> p = (Map<String, Object>) parse.get("biz_product_detail_query_response");
		Map<String,Object> v =(Map<String, Object>) p.get("result");
		return(String) v.get("introduction");
	}

	/**
	 *   1.1.7获取移动端样式
	 */
	public static void getmobilewarestyleandjsbywareid(String sku){
		String params=ApiUrl.getParams("jd.kpl.open.item.getmobilewarestyleandjsbywareid", "{\"sku\": "+sku+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
	
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("jd_kpl_open_item_getmobilewarestyleandjsbywareid_response");
			
		}
	}
	
	/**
	 *  1.1.8查询商品上下架状态接口
	 */
	public static List<Map> productState(String skus,List<Map> ztGoodsList){
		String params=ApiUrl.getParams("biz.product.state.query", "{\"sku\": \""+skus+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		/*List<Map> ztList=new ArrayList<Map>();
		*/
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_state_query_response");
			
			boolean success=job.getBoolean("success");
			if(success){
				JSONArray result=job.getJSONArray("result");//sku ,分隔
				if(result!=null && result.size()>0){
					for(int i=0;i<result.size();i++){
						int state=result.getJSONObject(i).getInteger("state");
						if(state==0) {
							String sku = result.getJSONObject(i).getString("sku");
							for (int j = 0; j < ztGoodsList.size(); j++) {
								if (ztGoodsList.get(j).get("code").toString().equals(sku)) {
									ztGoodsList.remove(j);
								}
							}
						}
					}
				}
			}
		}
		return ztGoodsList;
	}
	
	/**
	 *  1.1.9查询所有图片信息接口
	 */
	public static String skuImageQuery(String sku){
		
		Productimg productimg=new Productimg();
		String params=ApiUrl.getParams("biz.product.skuImage.query", "{\"sku\": "+sku+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		String path="";
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_skuImage_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");
				JSONArray jaa=result.getJSONArray(""+sku);
				if(jaa!=null && jaa.size()>0){
					
					for(int i=0;i<jaa.size();i++){
						JSONObject jobj=jaa.getJSONObject(i);
						path+="http://img13.360buyimg.com/vc/"+jobj.getString("path")+"|";
					}
					
					
				}
				
			}
		}
		return path;
	}

	/**
	 *  1.1.10查询商品好评度接口
	 */
	public static JSONArray commentSummarys(String sku){
		String params=ApiUrl.getParams("biz.product.commentSummarys.query", "{\"sku\": "+sku+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);

		List<Product> ppList=new ArrayList<Product>();

		if(StringUtils.isNotBlank(resultToken)){

			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_commentSummarys_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				return  job.getJSONArray("result");
			}
		}
		return null;
	}
	
	/**
	 *  1.1.11查询商品区域购买限制接口
	 */
	public static JSONArray checkAreaLimit(String sku,Integer province,Integer city,Integer county,Integer townbid){
		
		String params=ApiUrl.getParams("biz.product.checkAreaLimit.query", "{\"skuIds\": \""+sku+"\",\"province\": "+province+",\"city\": "+city+",\"county\": "+county+",\"Town\": "+townbid+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		JSONArray result=null;
		
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_checkAreaLimit_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				 result=job.getJSONArray("result");
				
			
			}
		}
		return result;
	}
	
	/**
	 *  1.1.13查询赠品信息接口
	 */
	public static void skuGift(){
		
		String params=ApiUrl.getParams("biz.product.skuGift.query", "{\"sku\": 2745761,\"province\": 11,\"city\": 0,\"county\": 0,\"Town\": 0}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_skuGift_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");
			
			}
		}
	}
	
	/**
	 *  1.1.14运费查询接口       ***********************
	 */
	public static Double freight(String skuids,Integer province,Integer city,Integer county,Integer townbid){
		double freight=0d;
		String params=ApiUrl.getParams("biz.order.freight.get", "{\"sku\": "+skuids+",\"province\": "+province+",\"city\": "+city+",\"county\": "+county+",\"Town\": "+townbid+",\"paymentType\":4}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		
		
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_order_freight_get_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");
				 freight=result.getDouble("freight");
			
			}
		}
		return freight;
	}
	
	
	/**
	 *  1.4.4批量获取库存接口（新增）       ***********************
	 */
	public static boolean getnewstockbyid(Long skuId,int num,String area){
	
		//{"area":"1_2801_2800","skuNums":"[{skuId: 569172,num:101}]"}
		String skuids="[{skuId: "+skuId+",num:"+num+"}]";
		String params=ApiUrl.getParams("jd.kpl.open.getnewstockbyid.query", "{\"skuNums\": \""+skuids+"\",\"area\":\""+area+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		boolean resultBool=false;
		if(StringUtils.isNotBlank(resultToken)){
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("jd_kpl_open_getnewstockbyid_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONArray result=job.getJSONArray("result");
				for(int i=0;i<result.size();i++){
					JSONObject jobject=result.getJSONObject(i);
					String stockStateId = jobject.get("stockStateId").toString();
					if("34".equals(stockStateId)){//无货
						resultBool=true;
					}else{//有货
						resultBool=false;
					}
				}
				
			
			}
		}
		return resultBool;
	}
	
	/**
	 *  1.1.15商品可售验证接口
	 */
	public static List<Map> productSkuCheck(String skuids,List<Map> ztGoodsList){
		
		String params=ApiUrl.getParams("biz.product.sku.check", "{\"skuIds\": \""+skuids+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
	/*	List<Map> ztList=new ArrayList<Map>();
		*/
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_product_sku_check_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONArray result=job.getJSONArray("result");
			
				for(int i=0;i<result.size();i++){
					int saleState=result.getJSONObject(i).getInteger("saleState");
					if(saleState==0){
						String sku=result.getJSONObject(i).getString("sku");
						for(int j=0;j<ztGoodsList.size();j++){
							if(ztGoodsList.get(j).get("code").toString().equals(sku)){
								ztGoodsList.remove(j);
							}
						}
					}
				}
			}
		}
		
		return ztGoodsList;
	}

	/**
	 *  商品可售验证接口 (单个商品)
	 * @param sluId
	 * @return
	 */
	public static Boolean productSkuChec(String sluId){
		String params=ApiUrl.getParams("biz.product.sku.check", "{\"skuIds\": \""+sluId+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		ProductSkuChecVo parse = GsonUtil.parse(resultToken, ProductSkuChecVo.class);
		List<ProductSkuChecVo.BizProductSkuCheckResponseBean.ResultBean> beanList = parse.getBiz_product_sku_check_response().getResult();
		ProductSkuChecVo.BizProductSkuCheckResponseBean.ResultBean bean = beanList.get(0);
		if (bean.getSaleState() != 1) {
			return false;
		}
		return true;
	}
	
	/**
	 *  1.1.16查询商品延保接口     **********
	 */
	public static void productYanbao(){
		
		String params=ApiUrl.getParamsV2("biz.product.yanbao.sku.query", "skuIds=2317745,1178224&province=22&city=1930&county=0&town=0");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		
		
		if(StringUtils.isNotBlank(resultToken)){
			
			
			JSONObject jo=JSONObject.parseObject(resultToken);
			
			boolean success=jo.getBoolean("success");
			if(success){
				JSONObject result=jo.getJSONObject("result");
			
			}
		}
	}
	
	/**
	 *  1.1.18查询分类信息接口（新）
	 */
	public static JSONArray productCategorys(int catClass,int parentId){
		
		String params=ApiUrl.getParams("jd.biz.product.getcategorys", "{\"pageNo\": 1,\"pageSize\":5000,\"parentId\":\""+parentId+"\",\"catClass\":\""+catClass+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
		
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("jd_biz_product_getcategorys_response");
			boolean success=false;
			try{
			 success=job.getBoolean("success");
			}catch(Exception ex){
				return null;
			}
			if(success){
				JSONObject result=job.getJSONObject("result");
				JSONArray ja=result.getJSONArray("categorys");
				return ja;
			}
		}
		return null;
	}
	
	/**
	 *  1.1.18查询分类信息接口（新）
	 */
	public static void allProvinces(){
		
		String params=ApiUrl.getParams("biz.address.allProvinces.query","{}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
		
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_address_allProvinces_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");
				
			}
		}	
	}
	/**
	 * 二级地址
	 */
public static JSONObject citysByProvinceId(Integer id){
		
		String params=ApiUrl.getParams("biz.address.citysByProvinceId.query","{\"id\":"+id+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		
		if(StringUtils.isNotBlank(resultToken)){
		
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_address_citysByProvinceId_query_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONObject result=job.getJSONObject("result");
				return result;
			}
		}	
		return null;
	}
/**
 * 三级地址
 */
public static JSONObject countysByCityId(Integer id){
	
	String params=ApiUrl.getParams("biz.address.countysByCityId.query","{\"id\":"+id+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_address_countysByCityId_query_response");
		boolean success=job.getBoolean("success");
		if(success){
			JSONObject result=job.getJSONObject("result");
			
			return result;
		}
	}	
	return null;
}

/**
 * 四级地址
 */
public static JSONObject townsByCountyId(Integer id){
	
	String params=ApiUrl.getParams("biz.address.townsByCountyId.query","{\"id\":"+id+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_address_townsByCountyId_query_response");
		boolean success=job.getBoolean("success");
		if(success){
			JSONObject result=job.getJSONObject("result");
		
			return result;
		}
	}	
	return null;
}

public static JSONObject checkarea(Integer provinceId,Integer cityId,Integer countyId){
	
	String params=ApiUrl.getParams("jd.kpl.open.area.checkarea","{\"provinceId\":"+provinceId+",\"cityId\":"+cityId+",\"countyId\":"+countyId+",\"townId\":0}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("jd_kpl_open_area_checkarea_response");
		boolean success=job.getBoolean("success");
		if(success){
			JSONObject result=job.getJSONObject("result");
			
			return result;
		}
	}	
	return null;
}

/**
 *  1.1.21商品关联属性的商品集查询接口（查询SPU）
 */
public JSONArray shopinfo(String jsonStr,String goodspool,String goodsid){
	//"{"set":["1231906","6000114"]}"
	String params=ApiUrl.getParams("jd.kpl.open.shopinfo.sku", jsonStr);
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	Date da=new Date();
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("jd_kpl_open_shopinfo_sku_response");
		
		String code="-1";
		try{
			code=job.get("code").toString();
		}catch(Exception ex){
			return null;
		}
		if("0".equals(code)){
			JSONObject result=job.getJSONObject("result");
			
			JSONObject joResult=JSONObject.parseObject(jsonStr);
			JSONArray jaResult=joResult.getJSONArray("set");
			for(int i=0;i<jaResult.size();i++){
				String skuId=jaResult.get(i).toString();
				JSONArray jja=result.getJSONArray(skuId);
				for(int g=0;g<jja.size();g++){
					JSONObject jbje=jja.getJSONObject(g);
					String size_quence=jbje.get("size_quence").toString();
					String color_quence=jbje.get("color_quence").toString().trim();
					if(StringUtils.isBlank(size_quence)){
						size_quence="1";
					}
					if(StringUtils.isBlank(color_quence)){
						color_quence="1";
					}
					//String size=jbje.get("size").toString().trim();
					String color="";
					
					if(jbje.get("color")!=null){
						color=jbje.get("color").toString().trim();
					}
					
					String size="";
					if(jbje.get("size")!=null){
						size=jbje.get("size").toString().trim();
					}
					String max_purch_qty=jbje.get("max_purch_qty").toString();//最大限购
					String image_path=jbje.get("image_path").toString();
					
					String erpPid=jbje.get("erpPid").toString();
					String sku=jbje.get("skuId").toString();
					ZtGoods zgds=new ZtGoods();
					zgds.setCode(sku);
					zgds=ztGoodsService.getByCode(zgds);
					if(zgds==null || StringUtils.isBlank(zgds.getId())){
						continue;
					}
					String pname=jbje.get("pname").toString();
					
					ZtColor ztColor=new ZtColor();
					ztColor.setTitle(StringUtils.isBlank(color)?"全部":color);
					ztColor.setImg(image_path);
					
					ZtGoods ztGoods=new ZtGoods();
					/*ztGoods.setCode(skuId);
					ztGoods.setGoodspool(goodspool);
					 ztGoods=ztGoodsService.getByCode(ztGoods);*/
					ztGoods.setId(goodsid);
					ztColor.setZtGoods(ztGoods);
					ztColor.setSku(sku);
					
					ztColor.setPname(pname);
					ztColor.setQuence(Integer.valueOf(color_quence));
					ztColor.setErpid(erpPid);
					ZtColor ztc=ztColorService.getByGoods(ztColor);
					if(ztc!=null){
						ztColor=ztc;
					}else{
						ztColor.setCreateDate(da);
						ztColorService.save(ztColor);
					}
					if(StringUtils.isNotBlank(size)){
					ZtSpecifications ztSpecifications=new ZtSpecifications();
					ztSpecifications.setZtColor(ztColor);
					ztSpecifications.setQuence(Integer.valueOf(size_quence));
					ztSpecifications.setPname(pname);
					ztSpecifications.setSku(sku);
					ztSpecifications.setErpid(erpPid);
					
					ZtSpecifications zp=ztSpecificationsService.getBySku(ztSpecifications);
					if(zp==null){
						
					ztSpecifications.setXgnum(Integer.valueOf(max_purch_qty));
					ztSpecifications.setName(StringUtils.isBlank(size)?"全部":size);
					ztSpecifications.setCreateDate(da);
					
					
					
					ztSpecificationsService.save(ztSpecifications);
					
					}
					
					}
				}
			}
			
		}
	}
	return null;
}

/**
 *  1.2.2批量查询价格
 */
public Map getPrice(String skuids){
	
	String params=ApiUrl.getParams("biz.price.sellPrice.get", "{\"sku\": \""+skuids+"\"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	Map map=new HashMap();
	//List<Map> ztList=new ArrayList<Map>();
	
	if(StringUtils.isNotBlank(resultToken)){
		
		
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_price_sellPrice_get_response");
		boolean success=job.getBoolean("success");
		if(success){
			JSONArray result=job.getJSONArray("result");
		
			for(int i=0;i<result.size();i++){
		
				JSONObject jobjobj=result.getJSONObject(i);
				//supplyPrice    供应价
				double price = jobjobj.get("price")==null?-1:Double.valueOf(jobjobj.get("price").toString());
				map.put("supplyPrice",price);
				//origPrice
				double jdPrice = jobjobj.get("jdPrice")==null?-1:Double.valueOf(jobjobj.get("jdPrice").toString());
				map.put("origPrice",jdPrice);
			}
		}
	}
	return map;
}

/**
 *  1.2.2批量查询价格
 */
public static synchronized ZtGoods sellPrice(String skuids,ZtGoods ztGoods){
	
	String params=ApiUrl.getParams("biz.price.sellPrice.get", "{\"sku\": \""+skuids+"\"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
		
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_price_sellPrice_get_response");
		boolean success=job.getBoolean("success");
		if(success){
			JSONArray result=job.getJSONArray("result");
		
			for(int i=0;i<result.size();i++){
		
				JSONObject jobjobj=result.getJSONObject(i);
				//supplyPrice
				double price = jobjobj.get("price")==null?0:Double.valueOf(jobjobj.get("price").toString());
				String skuId = jobjobj.get("skuId").toString();
				ztGoods.setCode(skuId);
				//origPrice
				double jdPrice = jobjobj.get("jdPrice")==null?0:Double.valueOf(jobjobj.get("jdPrice").toString());
				double jdsPrice = getJdsPrice(skuId);
			/*	if(ztGoods.getSupplyPrice()==price && ztGoods.getOrigPrice()==jdPrice){//京东价和协议价都没有变化
					continue;
				}*/
				BigDecimal b1 = new BigDecimal(String.valueOf(jdPrice));
				BigDecimal b2 = new BigDecimal(String.valueOf(price));
				ztGoods.setSupplyPrice(price);
				if(jdsPrice>0D){
					ztGoods.setJdSprice(jdsPrice);
					ztGoods.setOrigPrice(jdsPrice);
					BigDecimal b3 = new BigDecimal(String.valueOf(jdsPrice));
					ztGoods.setDiff(Double.valueOf(new java.text.DecimalFormat("#.00").format(b3.subtract(b2).doubleValue())));
					ztGoods.setDepo(Double.valueOf(new java.text.DecimalFormat("#.00").format(((double)price/jdsPrice)*100)));
					if(!"2".equals(ztGoods.getTag())){//按规则定价 0是折扣定价   1是毛利额定价   2是自定义定价
						ztGoods=TaskUtils.fixPrice(ztGoods);
						if(ztGoods.getOrigPrice()==jdsPrice){//按实时价计算的
							ztGoods.setJdSprice(jdsPrice);
							ztGoods.setOrigPrice(jdPrice);
						}
					}
				}else {
					ztGoods.setOrigPrice(jdPrice);
					ztGoods.setJdSprice(jdsPrice);
					ztGoods.setDiff(Double.valueOf(new java.text.DecimalFormat("#.00").format(b1.subtract(b2).doubleValue())));
					ztGoods.setDepo(Double.valueOf(new java.text.DecimalFormat("#.00").format(((double)price/jdPrice)*100)));
					if(!"2".equals(ztGoods.getTag())){//按规则定价 0是折扣定价   1是毛利额定价   2是自定义定价
						ztGoods=TaskUtils.fixPrice(ztGoods);
					}
				}
			}
			if(result.size()==0){
				ztGoods=TaskUtils.fixPrice(ztGoods);
			}
		}
	}
	
	return ztGoods;
}

	/**
	 *  1.2.2批量查询价格
	 */
	public static synchronized ZtGoods refreshPrice(String skuids,ZtGoods ztGoods){

		String params=ApiUrl.getParams("biz.price.sellPrice.get", "{\"sku\": \""+skuids+"\"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);

		if(StringUtils.isNotBlank(resultToken)){

			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_price_sellPrice_get_response");
			boolean success=job.getBoolean("success");
			if(success){
				JSONArray result=job.getJSONArray("result");

				for(int i=0;i<result.size();i++){

					JSONObject jobjobj=result.getJSONObject(i);
					//supplyPrice
					double price = jobjobj.get("price")==null?0:Double.valueOf(jobjobj.get("price").toString());
					String skuId = jobjobj.get("skuId").toString();
					ztGoods.setCode(skuId);
					//origPrice
					double jdPrice = jobjobj.get("jdPrice")==null?0:Double.valueOf(jobjobj.get("jdPrice").toString());
					double jdsPrice = getJdsPrice(skuId);
					/*	if(ztGoods.getSupplyPrice()==price && ztGoods.getOrigPrice()==jdPrice){//京东价和协议价都没有变化
							continue;
						}*/

					BigDecimal b1 = new BigDecimal(String.valueOf(jdPrice));
					BigDecimal b2 = new BigDecimal(String.valueOf(price));
					ztGoods.setSupplyPrice(price);
					if(jdsPrice>0D){
						ztGoods.setOrigPrice(jdsPrice);
						BigDecimal b3 = new BigDecimal(String.valueOf(jdsPrice));
						ztGoods.setDiff(Double.valueOf(new java.text.DecimalFormat("#.00").format(b3.subtract(b2).doubleValue())));
						ztGoods.setDepo(Double.valueOf(new java.text.DecimalFormat("#.00").format(((double)price/jdsPrice)*100)));
					}else {
						ztGoods.setOrigPrice(jdPrice);
						ztGoods.setJdSprice(jdsPrice);
						ztGoods.setDiff(Double.valueOf(new java.text.DecimalFormat("#.00").format(b1.subtract(b2).doubleValue())));
						ztGoods.setDepo(Double.valueOf(new java.text.DecimalFormat("#.00").format(((double)price/jdPrice)*100)));
					}

					ztGoods=TaskUtils.fixPrice(ztGoods);
					if(ztGoods.getOrigPrice()==jdsPrice){//按实时价计算的
						ztGoods.setJdSprice(jdsPrice);
						ztGoods.setOrigPrice(jdPrice);
					}
				}
				if(result.size()==0){
					ztGoods=TaskUtils.fixPrice(ztGoods);
				}
			}
		}

		return ztGoods;
	}


/**
 *  1.2.2批量查询价格
 */
public static JSONArray getSellPrice(String skuids){
	
	String params=ApiUrl.getParams("biz.price.sellPrice.get", "{\"sku\": \""+skuids+"\"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	JSONArray result=new JSONArray();
	//List<Map> ztList=new ArrayList<Map>();
	
	if(StringUtils.isNotBlank(resultToken)){
		
		
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_price_sellPrice_get_response");
		boolean success=job.getBoolean("success");
		if(success){
			 result=job.getJSONArray("result");
			
		}
	}
	
	return result;
}

/**
 * 2.1.2统一下单接口
 */
public static JSONObject orderUniteSubmit(String orderinfo){
	
	String params=ApiUrl.getParams("biz.order.unite.submit",orderinfo);
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);


	if(StringUtils.isNotBlank(resultToken)){

		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_order_unite_submit_response");

		return job;
	}
	return null;
}


/**
 * 2.1.3确认预占库存订单接口
 */
public static boolean occupyStock(String jdOrderId){
	
	String params=ApiUrl.getParams("biz.order.occupyStock.confirm","{\"jdOrderId\": "+jdOrderId+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_order_occupyStock_confirm_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			return true;
		}else{//下单失败
			return false;
		}
	}	
	return false;
}


/**
 * 2.1.4发起支付接口
 */
public static JSONObject orderDoPay(String jdOrderId){
	
	String params=ApiUrl.getParams("biz.order.doPay","{\"jdOrderId\": "+jdOrderId+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_order_doPay_response");

		boolean success=job.getBoolean("success");
		if(success){//下单成功
			JSONObject result=job.getJSONObject("result");
			
			return result;
		}else{//下单失败
			
		}
	}	
	return null;
}

/**
 *2.1.5取消未确认订单接口
 */
public static JSONObject cancelorder(String jdOrderId){
	
	String params=ApiUrl.getParams("biz.order.cancelorder","{\"jdOrderId\": "+jdOrderId+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		JSONObject job=jo.getJSONObject("biz_order_cancelorder_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			JSONObject result=job.getJSONObject("result");
		
			return result;
		}else{//下单失败
			
		}
	}	
	return null;
}

/**
 * 2.1.6查询京东订单信息接口
 */
public static JSONObject jdOrderQuery(String jdOrderId){
	//queryExts=jdOrderState
	String params=ApiUrl.getParams("jd.kpl.open.selectjdorder.query","{\"jdOrderId\": "+jdOrderId+",\"queryExts\":\"jdOrderState\"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("jd_kpl_open_selectjdorder_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			JSONObject result=job.getJSONObject("result");
			//int jdOrderState=result.getInteger("jdOrderState");//
		/*	1.新单
			2.等待支付
			3.等待支付确认
			4.延迟付款确认
			5.订单暂停
			6.店长最终审核
			7.等待打印
			8.等待出库
			9.等待打包
			10.等待发货
			11.自提途中
			12.上门提货
			13.自提退货
			14.确认自提
			16.等待确认收货
			17.配送退货*/
			
			return result;
		}else{//下单失败
			
		}
	}	
	return null;
}

/**
 * 2.1.8订单反查接口
 */
public static String jdOrderIDByThridOrderID(String thirdOrder){
	
	String params=ApiUrl.getParams("biz.order.jdOrderIDByThridOrderID.query","{\"thirdOrder\": "+thirdOrder+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_order_jdOrderIDByThridOrderID_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/**
 * 2.1.9查询配送信息接口
 */
public static String orderTrack(String jdOrderId){
	
	String params=ApiUrl.getParams("biz.order.orderTrack.query","{\"jdOrderId\": "+jdOrderId+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_order_orderTrack_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


	/**
	 *  2.1.7 查询京东订单信息接口（新）
	 * @param jsonStr
	 */
	public static JSONObject findProductOrderInfo(String jsonStr) {
		String params=ApiUrl.getParams("jd.kpl.open.selectjdorder.query","{\"jdOrderId\": "+jsonStr+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		JSONObject json = JSONObject.parseObject(resultToken);
		JSONObject info = json.getJSONObject("jd_kpl_open_selectjdorder_query_response");
		if (info.getBoolean("success")) {
			return info;
		}
		return null;
	}

/**
 * 1.2.2 新建订单查询接口
 */
public static String checkNewOrder(String date,int page){
	
	String params=ApiUrl.getParams("biz.order.checkNewOrder.query","{\"date\": \""+date+"\",\"page\":"+page+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_order_checkNewOrder_query_response");
	
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
		
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/**
 *  1.2.3查询妥投订单接口
 */
public static String checkDlokOrder(String date,int page){
	
	String params=ApiUrl.getParams("biz.order.checkDlokOrder.query","{\"date\": \""+date+"\",\"page\":"+page+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_order_checkDlokOrder_query_response");
	
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/**
 *  1.2.4查询拒收订单接口
 */
public static String checkRefuseOrder(String date,int page){
	
	String params=ApiUrl.getParams("biz.order.checkRefuseOrder.query","{\"date\": \""+date+"\",\"page\":"+page+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_order_checkRefuseOrder_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


/**
 *  2.3.2统一余额查询API接口 
 */
public static String balance(){
	
	String params=ApiUrl.getParams("biz.price.balance.get","{\"payType\":4}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_price_balance_get_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/*
 * 2.3.4查询余额明细接口
 */
public static String jincaiCredit(){
	
	String params=ApiUrl.getParams("biz.price.balancedetail.get","{}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_price_balancedetail_get_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}
	/*
	 * 2.3.4查询余额明细接口
	 */
	public static Page<BizPriceBalanceDetailDto.BizPriceBalanceDetailBean.ResultBean.Balance> balancedetail(String param){

		String params=ApiUrl.getParams("biz.price.balancedetail.get",param);
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		BizPriceBalanceDetailDto dto = GsonUtil.parse(resultToken,BizPriceBalanceDetailDto.class);
		Page<BizPriceBalanceDetailDto.BizPriceBalanceDetailBean.ResultBean.Balance> page = new Page<BizPriceBalanceDetailDto.BizPriceBalanceDetailBean.ResultBean.Balance>();
		if(dto.getBiz_price_balancedetail_get_response().isSuccess()){
			page.setPageNo(dto.getBiz_price_balancedetail_get_response().getResult().getPageNo());
			page.setPageSize(dto.getBiz_price_balancedetail_get_response().getResult().getPageSize());
			page.setCount(dto.getBiz_price_balancedetail_get_response().getResult().getTotal());
			page.setList(dto.getBiz_price_balancedetail_get_response().getResult().getBalances());
		}
		return page;
	}


/*
 *3.2校验某订单中某商品是否可以提交售后服务
 */
public static int availableNumberComp(String jdOrderId,Integer skuId){
	
	String params=ApiUrl.getParams("biz.afterSale.availableNumberComp.query","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"skuId\": "+skuId+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	int result=0;
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_afterSale_availableNumberComp_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getInteger("result");
		
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


/*
 *3.3查询支持的商品返回京东方式
 */
public static String wareReturnJdComp(String jdOrderId,Integer skuId){
	
	String params=ApiUrl.getParams("biz.afterSale.wareReturnJdComp.query","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"skuId\": "+skuId+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_afterSale_wareReturnJdComp_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/*
 *3.4查询支持的售后服务类型
 */
public static String customerExpectComp(String jdOrderId,Integer skuId){
	
	String params=ApiUrl.getParams("biz.afterSale.customerExpectComp.query","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"skuId\": "+skuId+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_afterSale_customerExpectComp_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


/*
 *3.5服务单创建申请
 */
public static String afsApplyCreate(String jdOrderId,Integer skuId){
	
	String params=ApiUrl.getParams("biz.afterSale.afsApply.create","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"skuId\": "+skuId+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_afterSale_customerExpectComp_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/*
 *3.5查询服务单概要信息
 */
public static String serviceListPage(String jdOrderId,Integer pageIndex,Integer pageSize){
	
	String params=ApiUrl.getParams("biz.afterSale.serviceListPage.query","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"pageIndex\": "+pageIndex+",\"pageSize\": "+pageSize+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
	
		JSONObject job=jo.getJSONObject("biz_afterSale_serviceListPage_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
		
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


/*
 *3.7填写客户发运信息
 */
public static String sendSku(String jdOrderId,Integer pageIndex,Integer pageSize){
	
	String params=ApiUrl.getParams("biz.afterSale.sendSku.update","{\"param\": {\"jdOrderId\": "+jdOrderId+",\"pageIndex\": "+pageIndex+",\"pageSize\": "+pageSize+"}}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_afterSale_serviceListPage_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/*
 *3.8查询服务单明细信息
 */
public static String serviceDetailInfo(String jdOrderId,Integer afsServiceId){
	
	String params=ApiUrl.getParams("biz.afterSale.serviceDetailInfo.query","{\"param\": {\"afsServiceId\": "+afsServiceId+"}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_afterSale_serviceDetailInfo_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}


/*
 *3.9取消服务单/客户放弃
 */
public static String auditCancel(String jdOrderId,Integer afsServiceId){
	
	String params=ApiUrl.getParams("biz.afterSale.auditCancel.query","{\"param\": {\"afsServiceId\": "+afsServiceId+"}");
	
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		
		JSONObject job=jo.getJSONObject("biz_afterSale_auditCancel_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
			return result;
		}else{//下单失败
			return result;
		}
	}	
	return result;
}

/**
 * 2.1.10获取京东预约日历
 */
public static void confirmreceived(String jdOrderId){
	
	String params=ApiUrl.getParams("jd.kpl.open.confirmreceived.query","{\"jdOrderId\": "+jdOrderId+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String result="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("jd_kpl_open_confirmreceived_query_response");
		
		boolean success=job.getBoolean("success");
		if(success){//下单成功
			result=job.getString("result");
			
		}else{//下单失败
			
		}
	}	
//	return result;
}
public static String jdorder="";
public static String jdorderid="";
/**
 * 2.1.10订单支付失败
 */
public void messageGet(int type){
	//{"id":推送id,"result":{"orderId":京东订单编号},"type":14,"time":推送时间}
	String params=ApiUrl.getParams("biz.message.get","{\"type\": "+type+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_message_get_response");
		
		boolean success=job.getBoolean("success");
		List<String> msgList=new ArrayList<String>();
		if(success){//成功
			if(cachedThreadPool==null){
			 cachedThreadPool=Executors.newCachedThreadPool();
			}
			JSONArray result=job.getJSONArray("result");
			for(int i=0;i<result.size();i++){
				JSONObject joject=result.getJSONObject(i);
				String joject_id=joject.get("id").toString();//消息id
				JSONObject jt=joject.getJSONObject("result");
				 jdorder=jt.get("orderId").toString();
				//msgList.add(joject_id);
				
				cachedThreadPool.execute(new Runnable() {			
					@Override
					public void run() {
						// TODO Auto-generated method stub
						if(StringUtils.isNotBlank(jdorder)){
							orderDoPay(jdorder);//支付
						}
					}
				});
				
				messageDel(joject_id);//
			}
			/*if(msgList!=null && msgList.size()>0){
				for(int i=0;i<msgList.size();i++){
					jdorderid=msgList.get(i);
					cachedThreadPool.execute(new Runnable() {			
						@Override
						public void run() {
							// TODO Auto-generated method stub
							if(StringUtils.isNotBlank(jdorder)){
								messageDel(jdorderid);//支付
							}
						}
					});
				}
				
			}*/
		}else{//失败
		
		}
	}	
}


/**
 * 2.1.10订单支付失败
 */
public List<ZtGoodsOrder> orderTrackGet(int type){
	//5代表该订单已妥投{"id":推送id,"result":{"orderId":"京东订单编号","state":"1是妥投，2是拒收"},"type":5,"time":推送时间}，
	String params=ApiUrl.getParams("biz.message.get","{\"type\": "+type+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	List<ZtGoodsOrder> listMap=new ArrayList<ZtGoodsOrder>();
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_message_get_response");
		
		boolean success=job.getBoolean("success");
		List<String> msgList=new ArrayList<String>();
		
		if(success){//成功
			if(cachedThreadPool==null){
			 cachedThreadPool=Executors.newCachedThreadPool();
			}
			JSONArray result=job.getJSONArray("result");
			for(int i=0;i<result.size();i++){
				JSONObject joject=result.getJSONObject(i);
				String joject_id=joject.get("id").toString();//消息id
				JSONObject jt=joject.getJSONObject("result");
				 jdorder=jt.get("orderId").toString();
				 String state=jt.get("state").toString();//1是妥投，2是拒收
				 
				 ZtGoodsOrder ztGoodsOrder=new ZtGoodsOrder();
				 ztGoodsOrder.setChannelorder(jdorder);
				 
				 ztGoodsOrder.setState(state);
				
				 listMap.add(ztGoodsOrder);
				
			//	msgList.add(joject_id);
				 messageDel(joject_id);//

			}
			/*if(msgList!=null && msgList.size()>0){
				for(int i=0;i<msgList.size();i++){
					jdorderid=msgList.get(i);
					cachedThreadPool.execute(new Runnable() {			
						@Override
						public void run() {
							// TODO Auto-generated method stub
							if(StringUtils.isNotBlank(jdorder)){
								messageDel(jdorderid);//支付
							}
						}
					});
				}
				
			}*/
		}else{//失败
		
		}
		
	}	
	return listMap;
}

private String jdorder_o;

//
/**
 * 2.1.10   sku价格
 */
public String skuPrice(int type){
	
	String params=ApiUrl.getParams("biz.message.get","{\"type\": "+type+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	String skus="";
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_message_get_response");
		
		boolean success=job.getBoolean("success");
		List<String> msgList=new ArrayList<String>();
		
		if(success){//成功
			if(cachedThreadPool==null){
			 cachedThreadPool=Executors.newCachedThreadPool();
			}
			JSONArray result=job.getJSONArray("result");
			for(int zi=0;zi<result.size();zi++){
		// {"id":推送id,"result":{"skuId":商品编号},"type":2,"time":推送时间}
				JSONObject joject=result.getJSONObject(zi);
				
				String joject_id=joject.get("id").toString();//消息id
				JSONObject jt=joject.getJSONObject("result");
				String skuId=jt.get("skuId").toString();
				
				skus+=skuId+",";
				
				
			//	msgList.add(joject_id);
				messageDel(joject_id);//

			}
			if(StringUtils.isNotBlank(skus)&& skus.length()>1){
				skus=skus.substring(0,skus.length()-1);
			}
			/*if(msgList!=null && msgList.size()>0){
				for(int i=0;i<msgList.size();i++){
					jdorderid=msgList.get(i);
					cachedThreadPool.execute(new Runnable() {			
						@Override
						public void run() {
							// TODO Auto-generated method stub
							if(StringUtils.isNotBlank(jdorder)){
								messageDel(jdorderid);//
							}
						}
					});
				}
				
			}*/
		}else{//失败
		
		}
		
	}
	return skus;
	
}
/**
 * 2.1.10订单支付失败
 */
public void pOrder(int type){
	
	String params=ApiUrl.getParams("biz.message.get","{\"type\": "+type+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
	if(StringUtils.isNotBlank(resultToken)){
	
		JSONObject jo=JSONObject.parseObject(resultToken);
		
		JSONObject job=jo.getJSONObject("biz_message_get_response");
		System.out.println(job);
		boolean success=job.getBoolean("success");
		List<String> msgList=new ArrayList<String>();
		
		if(success){//成功
			if(cachedThreadPool==null){
			 cachedThreadPool=Executors.newCachedThreadPool();
			}
			JSONArray result=job.getJSONArray("result");
			for(int zi=0;zi<result.size();zi++){
		// {"id":推送id,"result":{"pOrder":父订单id},"type":1,"time":推送时间}
				JSONObject joject=result.getJSONObject(zi);
				System.out.println(joject);
				String joject_id=joject.get("id").toString();//消息id
				JSONObject jt=joject.getJSONObject("result");
				 jdorder_o=jt.get("pOrder").toString();
				
					/*cachedThreadPool.execute(new Runnable() {			
						@Override
						public void run() {
							// TODO Auto-generated method stub
							
								
							
						}
					});*/
				 	vdost(jdorder_o);
					msgList.add(joject_id);
					
					//messageDel(joject_id);
					
			}
			if(msgList!=null && msgList.size()>0){
				for(int i=0;i<msgList.size();i++){
					jdorderid=msgList.get(i);
					cachedThreadPool.execute(new Runnable() {			
						@Override
						public void run() {
							// TODO Auto-generated method stub
							if(StringUtils.isNotBlank(jdorder)){
								messageDel(jdorderid);//支付
							}
						}
					});
				}
				
			}
		}else{//失败
		
		}
		
	}	
	
}


/**
 * 2.1.10推送消息的删除
 */
public static void messageDel(String type){
	//{"id":推送id,"result":{"orderId":京东订单编号},"type":14,"time":推送时间}
	String params=ApiUrl.getParams("biz.message.del","{\"id\": "+type+"}");
	String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
	
}

	/**
	 * 查询订单中的商品是否支持售后服务
	 * 业务数据（可提交售后数量）
	 * @param json
	 *
	 */
	public static AfterSaleDto afterSale(String json){
		String params = ApiUrl.getParams("biz.afterSale.availableNumberComp.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		AfterSaleDto dto = GsonUtil.parse(resultToken, AfterSaleDto.class);
		return dto;
	}

	/**
	 * 查询支持的商品返回京东方式
	 * 服务类型
	 * 上门取件(4)、客户发货(40)、客户送货(7)
	 * @param json
	 * @return
	 */
	public static List<StandByProductDto.StandByProduct.ResultBean> standByProduct(String json){
		String params = ApiUrl.getParams("biz.afterSale.wareReturnJdComp.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		StandByProductDto dto = GsonUtil.parse(resultToken, StandByProductDto.class);
		if (dto.getStandByProduct().isSuccess()) {
			return dto.getStandByProduct().getResult();
		}
		return new ArrayList<>();
	}

	/**
	 * 查询支持的售后服务类型
	 * 服务类型
	 * 退货(10)、换货(20)、维修(30)
	 * @param json
	 * @return
	 */
	public static List<AfterSaleStandByProductDto.AfterSaleStandByProduct.ResultBean> afterSaleStandByProduct(String json){
		String params = ApiUrl.getParams("biz.afterSale.customerExpectComp.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		AfterSaleStandByProductDto dto = GsonUtil.parse(resultToken, AfterSaleStandByProductDto.class);
		if (dto.getBiz_afterSale_customerExpectComp_query_response().isSuccess()) {
			return dto.getBiz_afterSale_customerExpectComp_query_response().getResult();
		}
		return new ArrayList<>();
	}

	/**
	 *  售后服务单创建申请
	 *  需要该配送单已经妥投
	 *
	 * @param json
	 */
	public static AfterSaleServiceCreateDto.AfterSaleAfsApplyCreateBean serviceApplication(String json){
		String params = ApiUrl.getParams("biz.afterSale.afsApply.create", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		AfterSaleServiceCreateDto createDto = GsonUtil.parse(resultToken, AfterSaleServiceCreateDto.class);
		return createDto.getBiz_afterSale_afsApply_create_response();

	}

	/**
	 *  查询服务单概要信息
	 *
	 * @param json
	 */
	public static ServiceSingleDto queryServiceApplication(String json){
		String params = ApiUrl.getParams("biz.afterSale.serviceListPage.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		ServiceSingleDto dto = GsonUtil.parse(resultToken, ServiceSingleDto.class);
		if (dto.getBiz_afterSale_serviceListPage_query_response().isSuccess()) {
			return dto;
		}
		return null;
	}

	/**
	 *  填写客户发运信息
	 *  需要调用查询服务单概要信息查询得到服务单号
	 * @param json
	 */
	public static Boolean fillInClientShippingInfo(String json){
		String params = ApiUrl.getParams("biz.afterSale.sendSku.update", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		if (!StringUtil.isEmpty(resultToken)) {
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_afterSale_sendSku_update_response");
			return job.getBoolean("success");
		}
		return Boolean.FALSE;
	}

	/**
	 *  查询服务单明细信息
	 *	根据服务单号查询服务单明细信息，并可通过appendInfoSteps获取额外的信息模块（售后地址信息、客户发货信息、跟踪信息、）
	 * @param json
	 */
	public static ServiceDetailInfoDto queryServiceDetailInfo(String json){
		String params = ApiUrl.getParams("biz.afterSale.serviceDetailInfo.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		ServiceDetailInfoDto dto = GsonUtil.parse(resultToken, ServiceDetailInfoDto.class);
		if (dto.getBiz_afterSale_serviceDetailInfo_query_response().isSuccess()) {
			return dto;
		}
		return null;
	}

	/**
	 * 取消服务单
	 * @param json
	 */
	public static Boolean auditCancel(String json){
		String params = ApiUrl.getParams("biz.afterSale.auditCancel.query", "{\"param\":" + json + "}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		if (!StringUtil.isEmpty(resultToken)) {
			JSONObject jo=JSONObject.parseObject(resultToken);
			JSONObject job=jo.getJSONObject("biz_afterSale_auditCancel_query_response");
			return job.getBoolean("success");
		}
		return Boolean.FALSE;
	}



	public static void main(String[] args) {
		System.out.println(cancelorder("97602929066"));
		/*params.put("jdOrderId", "94905458252");
		params.put("pageIndex", 1);
		params.put("pageSize", 10);*/
		//params.put("serviceIdList", Arrays.asList(587864624));
		//params.put("approveNotes", "同意");
		// 587735011 587762579 587762580 587772901
		//System.err.println(auditCancel(GsonUtil.toJson(params)));
		/*JSONObject orderinfoJo=new JSONObject();
		//21==1898==26453
		JSONArray ja=new JSONArray();
		//1961302  1599550   2888241
	//	d("2302819");
		JSONObject jajb=new JSONObject();
		jajb.put("skuId",1961302);
		jajb.put("num",3);
		jajb.put("bNeedAnnex",true);
		jajb.put("bNeedGift",false);
		ja.add(jajb);
		
		JSONObject jajb1=new JSONObject();
		jajb1.put("skuId",1599550);
		jajb1.put("num",1);
		jajb1.put("bNeedAnnex",true);
		jajb1.put("bNeedGift",false);
		ja.add(jajb1);
		
		JSONObject jajb2=new JSONObject();
		jajb2.put("skuId",2888241);
		jajb2.put("num",1);
		jajb2.put("bNeedAnnex",true);
		jajb2.put("bNeedGift",false);
		ja.add(jajb2);
		
		orderinfoJo.put("sku", ja);
		orderinfoJo.put("thirdOrder", "2019010217150400002");
		orderinfoJo.put("name", "刘昆");
		orderinfoJo.put("province", 21);
		orderinfoJo.put("city", 1898);
		orderinfoJo.put("county", 26453);
		orderinfoJo.put("town", 26471);
		orderinfoJo.put("address", "文三路101号");
		orderinfoJo.put("mobile", "13662391904");
		orderinfoJo.put("email", "1714850193@qq.com");//邮箱
		orderinfoJo.put("invoiceState", 2);
		orderinfoJo.put("invoiceType", 1);//1普通发票    2增值税发票
		orderinfoJo.put("selectedInvoiceTitle", 5);
		orderinfoJo.put("companyName", "广州领互科技有限公司");//发票抬头
		orderinfoJo.put("invoiceContent", 1);
		orderinfoJo.put("paymentType", 4);
		orderinfoJo.put("isUseBalance", 1);
		orderinfoJo.put("submitState", 0);
		
		//jdOrderIDByThridOrderID("2019050320532100001");
	//	orderTrack("94934767179");
		/*String params=ApiUrl.getParams("biz.order.orderTrack.query","{\"jdOrderId\": "+"94961476390"+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		String result="";
		if(StringUtils.isNotBlank(resultToken)){
		
			JSONObject jo=JSONObject.parseObject(resultToken);
			
			JSONObject job=jo.getJSONObject("biz_order_orderTrack_query_response");
			System.out.println(job);
		}*/
		new ProductPoolUtils().pOrder(1);
	//	orderDoPay("94742590671");
	
	}
	
	public void vdost(String jdorder_o) {
		JSONObject j = jdOrderQuery(jdorder_o);
		int type_order = j.getInteger("type");
		if (type_order == 1) {//拆分的订单
			List<ZtGoodsOrder> ztGoodsOrderList = new ArrayList<ZtGoodsOrder>();

			JSONArray jaah = j.getJSONArray("cOrder");
			if (jaah != null && jaah.size() > 0) {
				for (int i = 0; i < jaah.size(); i++) {
					JSONObject jojbb = jaah.getJSONObject(i);
					String pOrder = jojbb.get("pOrder").toString();
					String jdOrderId = jojbb.get("jdOrderId").toString();
					Double freight = jojbb.getDouble("freight");
					JSONArray jrray = jojbb.getJSONArray("sku");
					for (int g = 0; g < jrray.size(); g++) {
						JSONObject jje = jrray.getJSONObject(g);
						String skuId = jje.get("skuId").toString();
						ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
						ztGoodsOrder.setSku(skuId);
						ztGoodsOrder.setChannelPorder(pOrder);
						ztGoodsOrder.setFreight(freight);
						ztGoodsOrder.setChannelorder(jdOrderId);
						ztGoodsOrderList.add(ztGoodsOrder);
					}
				}
				ztGoodsOrderService.batchUpdateJDOrder(ztGoodsOrderList);
			}
		}

	}
	public static synchronized double getJdsPrice(String sku){

		try{
			String resultStr= HttpRequest.sendPost("https://item.m.jd.com/product/"+sku+".html", null);
			//System.out.println(resultStr);
			String startIndex="&yen;<em>";
			String endIndex="</em>.";
			int startInt=resultStr.indexOf(startIndex)+startIndex.length();
			int endInt=resultStr.indexOf(endIndex);
			String ss=resultStr.substring(startInt, endInt);

			String sss=resultStr.substring(endInt+endIndex.length()-1, endInt+endIndex.length()+2);

			String jdsPrice=ss+sss;
			return Double.valueOf(jdsPrice);
		}catch(Exception ex){
			return 0d;
		}
	}
	/**
	 *  商品上下架状态监听
	 * @param type
	 */
	public static List<ProductStateMessagePo.BizMessageGetResponseBean.ResultBeanX> messageProductState(String type){
		String params=ApiUrl.getParams("biz.message.get","{\"type\": "+type+"}");
		String resultToken = HttpXmlUtils.httpsRequest(ApiUrl.apiUrl, params);
		ProductStateMessagePo messagePo = GsonUtil.parse(resultToken, ProductStateMessagePo.class);
		if (messagePo.getBiz_message_get_response().isSuccess()) {
			return messagePo.getBiz_message_get_response().getResult();
		}
		return null;
	}
}
